﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_DoiPass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable Employee = (DataTable)Session["Employee"];
        if (Employee == null)
            Response.Redirect("login.aspx");
        txtxdmkmoi.Attributes.Add("onkeypress", "return clickButton(event,'" + btsua.ClientID + "')");
        txtmkmoi.Attributes.Add("onkeypress", "return clickButton(event,'" + btsua.ClientID + "')");
        txtmkcu.Attributes.Add("onkeypress", "return clickButton(event,'" + btsua.ClientID + "')");
    }
    protected void btsua_Click(object sender, EventArgs e)
    {
        ThanhVienController ThanhVienCTR = new ThanhVienController();
        DataTable table = (DataTable)Session["Employee"];
        string passnhap = ThanhVienCTR.MD5(txtmkcu.Text);
        string passlay = table.Rows[0]["MatKhau"].ToString();
        if (passnhap != passlay)
        {
            lbloimkcu.Text = "Mật Khẩu Cũ Chưa Chính Xác";
        }
        else
        {
            ThanhVienEntity ThanhVienE = new ThanhVienEntity();
            ThanhVienE.TenDangNhap = table.Rows[0]["TenDangNhap"].ToString();
            ThanhVienE.MatKhau = ThanhVienCTR.MD5(txtmkmoi.Text);
            
            ThanhVienCTR.fnC_UpdateMatKhau(ThanhVienE);
            Session["Employee"] = null;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert",
            "alert('Thay đổi mật khẩu thành công !Xin hãy đăng nhập lại');location.href='login.aspx'", true);
        }
    }
    protected void bttrolai_Click(object sender, EventArgs e)
    {
        Response.Redirect("thongtincanhan.aspx");
    }
}